package com.java2207.group1.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.java2207.group1.bo.CarerBo;
import com.java2207.group1.bo.OldManBo;
import com.java2207.group1.pojo.Carer;
import com.java2207.group1.pojo.OldMan;
import com.java2207.group1.service.CarerService;
import com.java2207.group1.service.OldManService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

/**
 * @author HLJ
 * @Date 2022/7/21 07
 */
@Component
@Scope("prototype")  // 设置多例模式
public class WebOldManListener extends AnalysisEventListener<OldManBo> {

    @Autowired
    private OldManService oldManService;

    @Override
    public void invoke(OldManBo data, AnalysisContext analysisContext) {

        // new 实体类拷贝数据
        OldMan oldMan = new OldMan();

        // 属性拷贝
        BeanUtils.copyProperties(data,oldMan);
        oldManService.addOldMan(oldMan);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }
}
